#!/usr/bin/node

const log = console.log,
      fs = require('fs');

switch(process.argv.length){
  case 4: {//hard link node 13-in.js src ink
    let src1 = process.argv[2];
    let lnk1 = process.argv[3];
    try{
      fs.linkSync(src1,lnk1);
    }catch(e){
      console.error(e.message);
      process.exit(2); 
    }
    break;
  }
  case 5: {//soft linnk node 13-in.js -s src lnk
    let opt = process.argv[2];
    let src = process.argv[3];
    let lnk = process.argv[4];
    if(opt === '-s'){
      try{
        fs.symlinkSync(src,lnk);
      }catch(e){
        console.error(e.message);
        process.exit(3);
      }
    }else{
      log('命令行参数不正确');
      process.exit(4);
    }
    break;
  }
  default:{
    console.eror('命令行参数不正确');
    process.exit(1);
  }
}

